/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import domain.controller.file.ImageController;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import util.J2meAppHelper;

/**
 *
 * @author Victorino
 */
public class InicialForm implements CommandListener, AppForm {

    private List menu = new List("Desktop", List.IMPLICIT);
    private int INDEX_CONFIGURATION;
    private int INDEX_EXIT;
    private int INDEX_SEARCH;
    private Command cmdExit = new Command("Sair", Command.EXIT, 0);
    private Command cmdSelect = new Command("Selecionar", Command.ITEM, 1);

    protected InicialForm() {
        
    }
    
    /*public String getAplicationTitle(Cidade cit){
        
        return "Cidade: " + cit.getLabel();
    
    }*/
    
    
    public static InicialForm getInicialForm(){
        
        //return new InicialForm();
        return new InicialPortoSeguroForm();
        
    }

    public void commandAction(Command arg0, Displayable arg1) {

        if (menu.getSelectedIndex() == INDEX_EXIT || arg0.equals(cmdExit)) {
            J2meAppHelper.getInstance().exitMidlet();
        } else if (menu.getSelectedIndex() == INDEX_SEARCH) {
            J2meAppHelper.getInstance().changeForm(new CategoriaRaizForm(), true);
        } else if (menu.getSelectedIndex() == INDEX_CONFIGURATION) {
            J2meAppHelper.getInstance().changeForm(new ConfiguracaoForm());
        }
    }

    public void initialize(Object parameter) {
        this.menu.deleteAll();
        this.menu.removeCommand(cmdExit);
        this.menu.removeCommand(cmdExit);
        menu.addCommand(cmdExit);
        menu.addCommand(cmdSelect);
        menu.setCommandListener(this);
        
        INDEX_SEARCH = this.menu.append("Busca", ImageController.getInstance().getBuscaImagem());


    }
    
    public Displayable getDisplyable() {
        return menu;
    }

}
